package hui.zhang.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import hui.zhang.dao.transit.SignInfoRepository;
import hui.zhang.dao.transit.TransitInfoRepository;
import hui.zhang.domain.transit.SignInfo;
import hui.zhang.domain.transit.TransitInfo;
import hui.zhang.index.dao.WayBillIndexRepository;
import hui.zhang.service.transit.SignInfoService;

@Service
@Transactional
public class SignInfoServiceImpl implements SignInfoService {

	@Autowired
	private SignInfoRepository signInfoRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;
	
	@Autowired
	private WayBillIndexRepository wayBillIndexRepository; 

	@Override
	public void save(SignInfo model, String transitInfoId) {
		signInfoRepository.save(model);
		
		// 查询
		TransitInfo transitInfo = transitInfoRepository
				.findOne(Integer.parseInt(transitInfoId));
		transitInfo.setSignInfo(model);
		
		if(model.getSignType().equals("正常")) {
			transitInfo.setStatus("正常签收");
			// 更改运单状态
			transitInfo.getWayBill().setSignStatus(4);
			// 更改索引库
			wayBillIndexRepository.save(transitInfo.getWayBill());
		}
	} 
}
